Product
Introducing License Enforcement in Socket
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
@babel/plugin-transform-async-to-generator
Advanced tools
Turn async functions into ES2015 generators
The @babel/plugin-transform-async-to-generator package is a Babel plugin that transforms async functions into generator functions using the regenerator runtime, which is a part of the Facebook Regenerator project. This transformation allows async functions to be used in environments that do not natively support async/await syntax by converting them into ES2015/ES6 compatible code.
Transform async functions to generators
This feature allows developers to write asynchronous code using the modern async/await syntax and have it transformed into generator functions that are compatible with older JavaScript engines.
async function foo() {
await bar();
}
// Transforms to:
function foo() {
return regeneratorRuntime.async(function foo$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
_context.next = 2;
return regeneratorRuntime.awrap(bar());
case 2:
case "end":
return _context.stop();
}
}
}, null, this);
}
This package is similar to @babel/plugin-transform-async-to-generator in that it transforms async functions, but it does so by delegating to a specified module method, allowing for custom handling of async functions.
Fast-async is a Babel plugin that uses nodent to transform async/await functions. It is designed to be faster than the regenerator-based approach used by @babel/plugin-transform-async-to-generator and does not require a runtime.
While not a direct alternative, babel-preset-env includes the capability to transform async functions when the target environments specified do not support them natively. It uses @babel/plugin-transform-async-to-generator as part of its transformation suite when necessary.
Turn async functions into ES2015 generators
See our website @babel/plugin-transform-async-to-generator for more information.
Using npm:
npm install --save-dev @babel/plugin-transform-async-to-generator
or using yarn:
yarn add @babel/plugin-transform-async-to-generator --dev
v7.25.7 (2024-10-02)
babel-helper-validator-identifier
babel-traverse
babel-plugin-transform-classes
super()
check (@nicolo-ribaudo)babel-generator
infer
in compact mode (@nicolo-ribaudo)[no LineTerminator here]
after nodes (@nicolo-ribaudo)babel-types
babel-core
--experimental-require-module
(@nicolo-ribaudo)babel-helper-compilation-targets
, babel-helper-plugin-utils
, babel-preset-env
babel-plugin-proposal-destructuring-private
, babel-plugin-syntax-decimal
, babel-plugin-syntax-import-reflection
, babel-standalone
babel-generator
[no LineTerminator here]
before nodes (@nicolo-ribaudo)babel-plugin-transform-typescript
babel-types
BABEL_TYPES_8_BREAKING
at startup (@nicolo-ribaudo)FAQs
Turn async functions into ES2015 generators
The npm package @babel/plugin-transform-async-to-generator receives a total of 22,532,978 weekly downloads. As such, @babel/plugin-transform-async-to-generator popularity was classified as popular.
We found that @babel/plugin-transform-async-to-generator demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 4 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
Product
We're launching a new set of license analysis and compliance features for analyzing, managing, and complying with licenses across a range of supported languages and ecosystems.
Product
We're excited to introduce Socket Optimize, a powerful CLI command to secure open source dependencies with tested, optimized package overrides.